/**
 * 绘制物质
 */

import { IRelativePos,IPixelPos } from "./interface";

class Feature {
  pointArr: IRelativePos[] = [];
  isclosePath: boolean = true;
  isStroke: boolean = true;
  constructor(points: IRelativePos[]) {
    // 一般来说，绘制物体最好是用点连接点来绘制
   this.pointArr = points;
  }

  draw(ctx: CanvasRenderingContext2D, points:IPixelPos[]) {
    const path = new Path2D();
    points.forEach((point, index) => {
      if (index === 0) {
        path.moveTo(point.x, point.y);
      } else {
        path.lineTo(point.x, point.y);
      } 
    });
    this.isclosePath && path.closePath();
    this.isclosePath && ctx.fill(path);
    // 如果使用path2d 那么需要传入path ，如果是ctx.beginPath() 那么不需要传入path
    this.isStroke && ctx.stroke(path);
  }
}

export default Feature;
